package com.asset.dispoal.business.make;

import com.asset.dispoal.business.common.KeyValue;
import com.asset.dispoal.business.make.api.MakeService;
import com.asset.dispoal.business.make.dto.MakePageRequest;
import com.asset.dispoal.business.make.dto.MakePageResponse;
import com.asset.dispoal.business.make.dto.MakeReceiveCaseRequest;
import com.asset.dispoal.business.make.dto.MakeViewPageRequest;
import com.asset.dispoal.commom.menus.AgreementCaseSateMenu;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.mhuang.pacebox.springboot.core.permission.annotation.Permission;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author qr
 * @date 2022/5/18$
 */
@RestController
@RequestMapping("business/make")
@Api(value = "制作管理", tags = "制作管理")
public class MakeController {

    @Autowired
    MakeService makeService;

    @Permission(code = "caseManageMake:query", param = "cases.receive_user_id")
    @GetMapping("/queryPage")
    @ApiOperation(value = "制作分页查询", notes = "制作分页查询")
    public Result<PageVO<MakePageResponse>> queryPage(MakePageRequest request) {
        return makeService.queryPage(request);
    }

    @GetMapping("/queryViewPage")
    @ApiOperation(value = "制作查阅分页查询", notes = "制作查阅分页查询")
    public Result<PageVO<MakePageResponse>> queryViewPage(MakeViewPageRequest request) {
        return makeService.queryViewPage(request);
    }

    @PostMapping("receiveCase")
    @ApiOperation(value = "下单,制作，待立案案件", notes = "下单,制作，待立案案件")
    public Result receiveCase(@RequestBody MakeReceiveCaseRequest request) {
        return makeService.receiveCase(request);
    }

    @GetMapping("/queryState")
    @ApiOperation(value = "查询制作状态", notes = "查询制作状态")
    public Result<List<KeyValue<String, String>>> queryState() {
        return Result.ok(Stream.of(
                AgreementCaseSateMenu.DOWNLOAD_ORGER,
                AgreementCaseSateMenu.WAIT_RECV_ORDER,
                AgreementCaseSateMenu.MAKE,
                AgreementCaseSateMenu.MAKING
        ).map(stateEnum -> KeyValue.build(stateEnum.getLabel(), stateEnum.getValue())).collect(Collectors.toList()));
    }
}
